﻿using System;
using System.Collections.Generic;
using System.Text;
using PacMan3D.Utils;
using Tao.OpenGl;
using Tao.FreeGlut;

namespace PacMan3D.Objects
{
    public class Life : IRenderable, ICollidable
    {
        public Point3D Position { get; private set; }

        private float RadiusSize;

        private int Slices = 20;
        private int Stacks = 20;

        private RGBAColor Color;
        
        /// 
        /// Life Material 
        /// 
        private float[] Specular = { 1.0f, 1.0f, 1.0f, 1.0f };
        private int Shininess = 100;

        private int DisplayListId = 0;

        public Life(Point3D position, float radiusSize)
        {
            this.Position = position;
            this.Position.Y = radiusSize / 4.0f;
            this.RadiusSize = radiusSize / 6.0f;
            this.Color = new RGBAColor(StandardColors.Purple, 0.5f);

            this.DisplayListId = Gl.glGenLists(1);
            Gl.glNewList(this.DisplayListId, Gl.GL_COMPILE);
            Glut.glutSolidSphere(this.RadiusSize, this.Slices, this.Stacks);
            Gl.glEndList();
        }

        public override void DrawObject()
        {
            Gl.glEnable(Gl.GL_BLEND);
            Gl.glEnable(Gl.GL_LIGHTING);
            Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE_MINUS_SRC_ALPHA);
            
            Gl.glPushMatrix();  
                Gl.glTranslatef(this.Position.X, this.Position.Y, this.Position.Z);
                Gl.glColor4f(this.Color.Red, this.Color.Green, this.Color.Blue, this.Color.Alpha);
                Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, this.Specular);
                Gl.glMateriali(Gl.GL_FRONT, Gl.GL_SHININESS, this.Shininess);
                Gl.glCallList(this.DisplayListId);
            Gl.glPopMatrix();

            Gl.glDisable(Gl.GL_LIGHTING);
            Gl.glDisable(Gl.GL_BLEND);
        }

     
        #region ICollidable Members

        public float Size
        {
            get { return this.RadiusSize; }
        }


        #endregion
    }
}
